package com.grantheath.erebus.controller.transitionManagers.linearTransitionManagers.normalFlow
{
	import com.grantheath.erebus.model.enum.notifications.ErebusPreloaderNotifications;
	import com.grantheath.erebus.model.enum.notifications.ErebusTransitionNotifications;
	import com.grantheath.erebus.model.enum.names.ErebusProxyNames;
	import com.grantheath.erebus.model.interfaces.IErebusSiteTreeProxy;
	import com.grantheath.erebus.model.interfaces.IErebusPageNode;

	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**
	 * @author grantheath
	 */
	public class ErebusPageShownNormalFlowCommand extends SimpleCommand implements ICommand 
	{
		override public function execute(notification : INotification) : void
		{
			var siteTreeProxy : IErebusSiteTreeProxy = facade.retrieveProxy(ErebusProxyNames.SITE_TREE_PROXY) as IErebusSiteTreeProxy;
			var pageNode : IErebusPageNode = notification.getBody() as IErebusPageNode;

			
			siteTreeProxy.registerDisplayedPageNode(pageNode);
			trace("page shown: " + pageNode + "\tdisplayed nodes: " + siteTreeProxy.displayedPages);	
			if(siteTreeProxy.interuptTransition){
				sendNotification(ErebusTransitionNotifications.TRANSITION_INTERUPTED, pageNode);	
			} else {
				pageNode = siteTreeProxy.incrementDisplayQueue();
				if(pageNode){
					sendNotification(ErebusPreloaderNotifications.SHOW_PRELOADER, pageNode);
				} else {
					sendNotification(ErebusTransitionNotifications.PAGE_SHOW_PROCESS_COMPLETE);
					sendNotification(ErebusTransitionNotifications.TRANSITION_COMPLETE);
				}
			}
		}
	}
}
